package com.gxa.community.admin.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gxa.community.admin.mapper.user.UserSelfVoMapper;
import com.gxa.community.admin.service.user.UserService;
import com.gxa.community.core.pojo.dto.userdto.UserDto;
import com.gxa.community.core.pojo.vo.admin.user.UserSelfVo;
import com.gxa.community.core.utils.R;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author juran
 * @since 2022-07-18
 */
@RestController
@RequestMapping("/user")
@Log4j2
public class UserController {

    @Resource(name = "adminUser")
    UserService userService;
    @Autowired
    UserSelfVoMapper userSelfVoMapper;

    @ApiOperation("批量设置用户标签")
    @PostMapping("/addUserTags")
    public R addUserTags(@RequestBody UserDto userDto) {
        return userService.addUserTags(userDto);
    }

    @ApiOperation("查询用户信息")
    @PostMapping("/queryUserInfo")
    public R queryUserInfo(@RequestBody UserDto userDto,
                           int page,
                           int size) {
        return userService.queryUserInfo(userDto,
                ObjectUtils.isEmpty(page) ? 1 : page,
                ObjectUtils.isEmpty(page) ? 5 : size);
    }

    /**
     * 远程接口
     * 查询所有的自提点信息
     * @return
     */
    @GetMapping("/queryUsetAppList")
    private List<UserSelfVo> queryUsetAppList(){
        QueryWrapper <UserSelfVo> wrapper = new QueryWrapper<>();
        wrapper.isNull("invalid_tp");
        List<UserSelfVo> dtos = userSelfVoMapper.selectList(wrapper);
        return dtos;
    }

}
